﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Server;
using ComponentFactory.Krypton.Toolkit;

namespace Client
{
    /// <summary>
    /// Displays a File and Exposes functionality
    /// </summary>
    public partial class FileMessage : FileControlBase
    {
        public event SaveEventhandler Save;
        public event ForwardEventHandler Forward;
        public event FileReplyEventhandler Reply;
        public FileMessage()
        {
            InitializeComponent();
        }
        protected virtual void OnReply(object sender, ReplyChatEventArgs<FilePost> e)
        {
            Reply(sender, e); // Reply(this,e) kept throwing exceptions.
        }
        public FileMessage(FilePost newEntry)
        {
            InitializeComponent();
            myEntry = newEntry;
            this.User = myEntry.User;
            this.kryptonHeader1.Values.Heading = myEntry.LocalFile;
            this.kryptonHeader1.Values.Description= this.User;
            this.User = myEntry.User;
        }
        protected virtual void OnForward(ChatEventArgs<FilePost> e)
        {
            Forward(this, e);
        }
        protected virtual void OnSave(ChatEventArgs<FilePost> e)
        {
            Save(this, e);
        }
        public string FileLink
        {
            get { return this.myEntry.LocalFile; }
        }


        private void buttonSpecAny3_Click(object sender, EventArgs e)
        {
            OnSave(new ChatEventArgs<FilePost>(myEntry));
        }

        private void buttonSpecAny4_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(this.FileLink);
        }

        private void buttonSpecAny1_Click(object sender, EventArgs e)
        {
            OnForward(new ReplyChatEventArgs<FilePost>(myEntry, this.User));
        }

        private void buttonSpecAny2_Click(object sender, EventArgs e)
        {
            OnReply(this, new ReplyChatEventArgs<FilePost>(myEntry, this.User));
        }
        
    }
    public class FileControlBase : MessageBase<FilePost>
    { }
}
